package com.ayoka.parenting.ui.live;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.ayoka.parenting.R;
import com.jincp.common.dialog.BaseDialogBuilder;
import com.jincp.common.dialog.BaseDialogFragment;
import com.tencent.ticsdk.core.TICManager;

/**
 * =========================================================
 * @ProjectName: 
 * @ClassName: WhiteBoardDialog
 * @Description: 
 * @Author: jincp
 * @CreateDate: 2019/9/19 16:18
 * =========================================================
 */
public class WhiteBoardDialog extends BaseDialogFragment {

    public static WhiteBoardDialog newInstance(Builder builder) {
        WhiteBoardDialog dialog = new WhiteBoardDialog();
        Bundle bundle = getArgumentBundle(builder);
        dialog.setArguments(bundle);
        return dialog;
    }


    @Override
    protected void convertView(@Nullable final View container, final BaseDialogFragment dialogFragment) {
        //返回
        container.findViewById(R.id.iv_close).setOnClickListener(new CloseClickListener());

        FrameLayout frameLayout = container.findViewById(R.id.layout_white_board_container);
        if (TICManager.getInstance().getBoardController() != null) {
            TICManager.getInstance().getBoardController().setDrawEnable(false);
            View boardView = TICManager.getInstance().getBoardController().getBoardRenderView();

            if (boardView != null) {
                if (boardView.getParent() != null && boardView.getParent() instanceof ViewGroup) {
                    ((ViewGroup)boardView.getParent()).removeView(boardView);
                }
                try {
                    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
                    frameLayout.addView(boardView, layoutParams);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }


    @Override
    protected int getLayoutId() {
        return R.layout.dialog_white_board;
    }


    public static class Builder extends BaseDialogBuilder<Builder, WhiteBoardDialog> {

        @Override
        public WhiteBoardDialog build() {
            return WhiteBoardDialog.newInstance(this);
        }
    }
}